package robocup.component.infotypes;

import robocup.component.geometry.Vektor;

/**
 * This class holds all information taht are available for seen players. This is
 * an extension of DynamicObjectInfo, which holds values for position and speed.
 */
public class PlayerInfo
    extends DynamicObjectInfo {

  /**
   * Constant for friendly players.
   */
  public static final int FRIEND            = 0;

  /**
   * Constant for enemy players.
   */
  public static final int OPPONENT          = 1;

  /**
   * Constant, indicating that the team of the player is not known.
   */
  public static final int UNKNOWN           = 2;

  /**
   * The seen body-direction of the player.
   */
  private double          bodyDir;

  /**
   * The seen neck-angle of the player.
   */
  private double          headDir;

  /**
   * The type (team) of the player.
   */
  private int             type;

  /**
   * The seen pointing-direction for that player.
   */
  private double          pointDir;

  /**
   * Flag, indicating that the player has tackled.
   */
  private boolean         tackle;

  /**
   * Is the player a goalie?
   */
  private boolean         goalie;

  /**
   * The name of his team.
   */
  private String          teamName          = "";

  /**
   * Ths absolute position of that player.
   */
  private final Vektor          absPlayerPosition = Vektor.getDummyInstance();

  /**
   * Constructor, craetes a new PlayerInfo with all given data
   * 
   * @param cycle -
   *          the cycle, when it was seen
   * @param iType
   * @param iNumber -
   *          his trcot number
   * @param iDistance -
   *          the distance
   * @param iDirection -
   *          the direction
   * @param iDistChange -
   *          the distChange value
   * @param iDirChange -
   *          the dirChange value, both used for speed
   * @param iBodyDir -
   *          his body direction
   * @param iHeadDir -
   *          his head-direction
   * @param iPointDir -
   *          where he points at
   * @param iTackle -
   *          is he tackling
   * @param iGoalie -
   *          is he goalie
   */
  public PlayerInfo(
      final int cycle,
      final int iType,
      final int iNumber,
      final double iDistance,
      final double iDirection,
      final double iDistChange,
      final double iDirChange,
      final double iBodyDir,
      final double iHeadDir,
      final double iPointDir,
      final boolean iTackle,
      final boolean iGoalie) {

    super(cycle, iNumber, iDistance, iDirection, iDistChange, iDirChange);
    this.bodyDir = iBodyDir;
    this.headDir = iHeadDir;
    this.pointDir = iPointDir;
    this.tackle = iTackle;
    this.goalie = iGoalie;
    this.type = iType;
  }

  /**
   * @return Returns the players number.
   */
  public int getNumber() {

    return this.getId();
  }

  /**
   * @return Returns the bodyDir.
   */
  public double getBodyDir() {

    return this.bodyDir;
  }

  /**
   * @return true if teammate or self
   */
  public boolean isFriend() {

    return this.type == PlayerInfo.FRIEND;
  }

  /**
   * @return true if opponent
   */
  public boolean isOpponent() {

    return this.type == PlayerInfo.OPPONENT;
  }

  /**
   * @return Returns true, if the players team is not known.
   */
  public boolean isOfUnknownTeam() {

    return this.type == PlayerInfo.UNKNOWN;
  }

  /**
   * @return Returns the headDir.
   */
  public double getHeadDir() {

    return this.headDir;
  }

  /**
   * @return Returns the type.
   */
  public int type() {

    return this.type;
  }

  /**
   * @return Returns the debug-string for this info-object.
   */
  @Override
  public String toString() {

    return ("SeePlayer: " + this.getNumber() + " Dist:" + this.distance + " Dir:" + this.direction + " dDist:" + super
        .getDistChange() + " dDir:" + super.getDirChange() + " Type:" + this
        .getInfoType() + " Goalie" + this.isGoalie());
  }

  /**
   * @return Returns true, if the player was seen as goalie.
   */
  public boolean isGoalie() {

    return this.goalie;
  }

  /**
   * Setter for reusing the PlayerInfo sets the body direction
   * 
   * @param bodyDir
   */
  public void setBodyDir(final double bodyDir) {

    this.bodyDir = bodyDir;
  }

  /**
   * Setter for reusing the PlayerInfo sets if goalie or not
   * 
   * @param goalie
   */
  public void setGoalie(final boolean goalie) {

    this.goalie = goalie;
  }

  /**
   * Setter for reusing the PlayerInfo sets the head direction
   * 
   * @param headDir
   */
  public void setHeadDir(final double headDir) {

    this.headDir = headDir;
  }

  /**
   * Setter for reusing the PlayerInfo sets the point direction
   * 
   * @param pointDir
   */
  public void setPointDir(final double pointDir) {

    this.pointDir = pointDir;
  }

  /**
   * Setter for reusing the PlayerInfo sets if tackling
   * 
   * @param tackle
   */
  public void setTackle(final boolean tackle) {

    this.tackle = tackle;
  }

  /**
   * Setter for reusing the PlayerInfo sets the type
   * 
   * @param type
   */
  public void setType(final int type) {

    this.type = type;
  }

  /**
   * @return Returns the pointDir.
   */
  public double getPointDir() {

    return this.pointDir;
  }

  /**
   * @return Returns the tackle.
   */
  public boolean isTackle() {

    return this.tackle;
  }

  /**
   * @return Returns the calculatedPlayerPosition.
   */
  public Vektor getAbsPlayerPosition() {

    return this.absPlayerPosition;
  }

  /**
   * @param playerPosition
   *          The calculatedPlayerPosition to set.
   */
  public void setAbsPlayerPosition(final Vektor playerPosition) {

    this.absPlayerPosition.copy(playerPosition);
  }

  /**
   * @return Returns the name of the players team.
   */
  public String getTeamName() {

    return this.teamName;
  }

  /**
   * Sets the name of the players team.
   * 
   * @param teamName
   */
  public void setTeamName(final String teamName) {

    this.teamName = teamName;
  }

}
